package com.demostic.demostic_test.fragment;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Environment;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.accloud.cloudservice.AC;
import com.accloud.cloudservice.PayloadCallback;
import com.accloud.cloudservice.VoidCallback;
import com.accloud.service.ACException;
import com.accloud.service.ACObject;
import com.accloud.service.ACUserDevice;
import com.demostic.demostic_test.R;
import com.demostic.demostic_test.activity.LoginActivity;
import com.demostic.demostic_test.activity.MainActivity;
import com.demostic.demostic_test.utils.Constants;
import com.demostic.demostic_test.utils.DialogUtils;
import com.demostic.demostic_test.utils.MyLog;
import com.demostic.demostic_test.utils.ToastUtils;
import com.demostic.demostic_test.utils.UserUtils;
import com.fasterxml.jackson.core.util.MinimalPrettyPrinter;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.integration.android.IntentIntegrator;
import com.journeyapps.barcodescanner.BarcodeEncoder;
import com.tbruyelle.rxpermissions2.Permission;
import com.tbruyelle.rxpermissions2.RxPermissions;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import io.reactivex.functions.Consumer;

public class PersonalFragment extends Fragment implements View.OnClickListener {
    private RelativeLayout rl_exit;
    private LayoutInflater inflater;
    private Dialog logoutDialog;
    private Context context;
    @Override // android.support.v4.app.Fragment
    public View onCreateView(LayoutInflater inflater2, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater2.inflate(R.layout.fragment_personal, (ViewGroup) null);
        initView(view);
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        boolean isLogin = AC.accountMgr().isLogin();
        if (isLogin) {
            getNameAndAvatar();
            return;
        }
    }

    public void initView(View view) {
        this.context = getActivity();
        this.inflater = LayoutInflater.from(this.context);
        this.rl_exit = (RelativeLayout) view.findViewById(R.id.rl_exit);

        this.rl_exit.setOnClickListener(this);
    }


    @Override // android.view.View.OnClickListener
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_exit /* 2131755622 */:
                if (AC.accountMgr().isLogin()) {
                    View view_exit = this.inflater.inflate(R.layout.exit_dialog, (ViewGroup) null);
                    this.logoutDialog = DialogUtils.showUnifyDialog(this.context, view_exit);
                    initExitView(view_exit);
                    this.logoutDialog.show();
                    return;
                }
                ToastUtils.showToast(this.context, getString(R.string.personal_fragment_login_first));
                return;

            case R.id.tv_logout_confirm /* 2131755595 */:
                this.logoutDialog.dismiss();
                AC.accountMgr().logout();
                startActivity(new Intent(getActivity(), LoginActivity.class));
                return;
            case R.id.tv_logout_cancel /* 2131755596 */:
                this.logoutDialog.dismiss();
                return;
            default:
                return;
        }
    }



    public void initExitView(View view) {
        ((TextView) view.findViewById(R.id.tv_logout_cancel)).setOnClickListener(this);
        ((TextView) view.findViewById(R.id.tv_logout_confirm)).setOnClickListener(this);
    }

    public void getNameAndAvatar() {
        AC.accountMgr().getUserProfile(new PayloadCallback<ACObject>() {
            /* class com.demostic.demostic_test.fragment.PersonalFragment.AnonymousClass1 */

            public void success(ACObject acObject) {
//                if (!PersonalFragment.this.isOnStop) {
//                    String userName = (String) acObject.get("nick_name");
//                    if (!TextUtils.isEmpty(userName)) {
//                        PersonalFragment.this.tv_name.setText(userName);
//                    } else {
//                        PersonalFragment.this.tv_name.setText(PersonalFragment.this.getString(R.string.personal_fragment_set_username));
//                    }
//                }
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
            }
        });
    }
}
